package leetcode;

public class _0098 {
    /**
     * 验证二叉搜索树
     */
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    class Solution {
        public boolean isValidBST(TreeNode root) {
            return isValidBST(root,Long.MIN_VALUE,Long.MAX_VALUE);
        }
        public boolean isValidBST(TreeNode root, long left,long right){
            if(root ==null){
                return true;
            }
            long x = root.val;
            return x>left&&x<right&&isValidBST(root.left,left,x)&&isValidBST(root.right,x,right);
        }
    }
}
